package com.shunda.ysdgj.manager.controller.goods;

import com.shunda.ysdgj.manager.service.goods.GoodsBrandService;
import com.shunda.ysdgj.model.dto.base.IdsDto;
import com.shunda.ysdgj.model.dto.goods.GoodsBrandFindDto;
import com.shunda.ysdgj.model.entity.goods.GoodsBrand;
import com.shunda.ysdgj.model.vo.ResultVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "商品品牌接口")
@RestController
@RequestMapping("/api/v1/admin/goods/brand")
@RequiredArgsConstructor
public class GoodsBrandController {

    private final GoodsBrandService goodsBrandService;

    @Operation(summary = "获取所有商品品牌列表")
    @GetMapping("all")
    public ResultVo all() {
        return ResultVo.success(goodsBrandService.findAll());
    }

    @Operation(summary = "分页获取商品品牌列表")
    @PostMapping("list")
    public ResultVo list(@RequestBody GoodsBrandFindDto goodsBrandFindDto) {
        return ResultVo.success(goodsBrandService.findByPage(goodsBrandFindDto));
    }

    @Operation(summary = "添加商品品牌")
    @PostMapping("add")
    public ResultVo add(@RequestBody GoodsBrand goodsBrand) {
        if (!goodsBrandService.add(goodsBrand)) {
            return ResultVo.fail();
        }
        return ResultVo.success();
    }

    @Operation(summary = "修改商品品牌")
    @PostMapping("modify")
    public ResultVo modify(@RequestBody GoodsBrand goodsBrand) {
        if (!goodsBrandService.modify(goodsBrand)) {
            return ResultVo.fail();
        }
        return ResultVo.success();
    }

    @Operation(summary = "删除商品品牌")
    @PostMapping("delete")
    public ResultVo delete(@RequestBody IdsDto idsDto) {
        if (!goodsBrandService.deleteByIds(idsDto)) {
            return ResultVo.fail();
        }
        return ResultVo.success();
    }

}
